package com.rules.admin.login;

import java.security.MessageDigest;

public class Md5Util {
   //TODO
   public static String md5Encode(String userName, String userPwd) throws Exception {
      String code = userName + userPwd;
      MessageDigest messageDigest = MessageDigest.getInstance("MD5");
      messageDigest.update(code.getBytes("UTF-8"));
      byte[] bytes = messageDigest.digest();
      String md5Str = "";

      for(int i = 0; i < bytes.length; ++i) {

         int temp;
         if (bytes[i] < 0) {
            temp = 256 + bytes[i];
         } else {
            temp = bytes[i];
         }

         if (temp < 16) {
            md5Str = md5Str + "0";
         }

         md5Str = md5Str + Integer.toString(temp, 16);
      }

      return md5Str;
   }
}
